package com.compass.doctor.ui.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.compass.doctor.R;
import com.compass.doctor.callback.OnCustomItemClick;
import com.compass.framework.model.ScreenTag;

import java.util.List;

/**
 * Description： 医生科室和职称adapter
 * Date:2024/1/10 14:55
 */
public class DoctorPopAdapter extends BaseAdapter {

    private Context context;
    private List<ScreenTag> mList;
    private OnCustomItemClick onCustomItemClick;
    private View.OnClickListener mOnClickListener;
    public DoctorPopAdapter(Context context) {
        this.context = context;
        mOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Object tag = v.getTag();
                if (tag != null && onCustomItemClick != null) {
                    int position = (int) tag;
                    String id=String.valueOf(mList.get(position).getId());
                    onCustomItemClick.onItemCallBack(position, mList.get(position).getName(),id);
                }
            }
        };
    }

    public void setList(List<ScreenTag> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    public void setOnCustomItemClick(OnCustomItemClick onCustomItemClick) {
        this.onCustomItemClick = onCustomItemClick;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = View.inflate(context, R.layout.layout_popup_item, null);
        }

        TextView textView =convertView.findViewById(R.id.tv_screen_name);
        textView.setText(mList.get(position).getName());
        textView.setTag(position);
        textView.setOnClickListener(mOnClickListener);
        return convertView;


    }
}
